arrayHTML
Arrays Sandbox PanosP Revised

Printing an Array in a Horizontally Columned HTML Table

Problem
=======

We want to print array elements as an HTML table.

Solution
========

That's a straight forward task:

 function arrayTable(arr, tstyle, dstyle,		i, header) {
 	# dstyle is used for styling <td> data (table cells).
 	if (!dstyle)
 		dstyle = "style=\"border-style: inset; " \
			"border-width: 2px;\""
 	for (i in arr) {
 		if (!header) {
 			# tstyle is used for styling the table as a whole.
 			print "<table " (tstyle ? tstyle : \
 				"style=\"border-style: outset; " \
				"border-width: 1px;\"") ">"
 			header = 1
 		}
 		print "\t<tr>"
 		print "\t\t<td " dstyle ">"
 		print i
 		print "\t\t</td>"
 		print "\t\t<td " dstyle ">"
 		print arr[i]
 		print "\t\t</td>"
 		print "\t</tr>"
 	}
 	if (header)
 		print "</table>"
 }

Discussion
==========
Array elements are printed in random order.
To print an array in an ordered fashion we must
sort the array and _then_ use a function similar to the
above function to print the array. Of course, that
kind of function must iterate a number indexed array.

The `tstyle` and `dstyle` arguments are optional. If given,
they will be used as given, e.g.

  arrayTable(a, "class=\"tbarr\"", "class=\"arrel\"")

If not given, then a default styling is used. To avoid the default
styling at all we can supply arguments that contain just a space,
e.g. to avoid the inner syling (no border for table elements):

  arrayTable(a, "", " ")

In the above call we supply a space as the `dstyle` argument,
causing the `if&nbsp;(!dstyle)` check to fail, while we keep the
default styling for the table as a whole by supplying an empty
argument for `tstyle`, causing the `(tstyle&nbsp;?&hellip;` check
to fail, and thus use the default cell styling.

Author
======

Panos Papadopoulos
